/**************************************************
Class Name:FormatChecker
Author's Name: John Lawniczak
Date: 04-21-2010
Description of the class: This class will check 
	strings passed to them to see if they are 
	a certain format/pattern
***************************************/

public class FormatChecker {
	
	/**************************************************
	Method Name: nameMatchesFormatting
	Input to the method: String to check
	Output(Return value): boolean
	Brief description of the task: check to see if the 
		string matches the name pattern
	Author: John Lawniczak
	**************************************************/
	public static boolean nameMatchesFormatting(String name) {
		boolean ret = false;
		if(name.matches("\\D+ \\D+"))//make sure there are two groups of non number substrings seperated by a space
			ret=true;
		return ret;
	}

	/**************************************************
	Method Name: phoneNumberMatchesFormatting
	Input to the method: String to check
	Output(Return value): boolean
	Brief description of the task: check to see if the 
		string matches the Phone Number pattern
	Author: John Lawniczak
	**************************************************/
	public static boolean phoneNumberMatchesFormatting(String phoneNumber) {
		boolean ret=false;
		if(phoneNumber.matches("\\d{3}-\\d{3}-\\d{4}"))//make sure there are three integer substrings seperated by hyphens
			ret=true;
		return ret;
	}

	/**************************************************
	Method Name: addressMatchesFormatting
	Input to the method: String to check
	Output(Return value): boolean
	Brief description of the task: check to see if the 
		string matches the address pattern
	Author: John Lawniczak
	**************************************************/
	public static boolean addressMatchesFormatting(String address) {
		boolean ret = false;
		try{
			//split the input string into two seperate substrings to be evaluated seperatly
			String streetAddr = 	address.split(",")[0];
			String cityStateZip = 	address.split(",")[1];
			
			//first check to see that the street address is in the format "numbers, space, letters with spaces, optional # with optional numbers"
			//then that the city state and zip code is "space, letters, space two upper case letters, space, 5 numbers"
			if(	streetAddr.matches("\\d+\\s[A-Za-z\\s]+\\s??[#]??\\d*?")&&cityStateZip.matches("\\s[a-zA-Z]+\\s[A-Z]{2}?\\s\\d{5}?"))
			{
				ret=true;
			}
		}catch(Exception e){}
		return ret;
	}
}
